﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Bidder_ConfirmPayMent : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{//  public Int32 PayMentProjectId;  2007/08/22 马
    Int64 PayMentPSId;


    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                //  PayMentProjectId = SysFun.ToInt(Request.QueryString["ProjectId"]);   2007/08/22 马
                PayMentPSId = SysFun.ToLong(_Account.AccountId);
                if (Request.Form["chk"] == "确认回款单" && Request.Form["upcheck"] != null)
                {
                    string StrSql, PaymentIdString,updateinsert;
                    Db db = new Db();
                    PaymentIdString = Request.Form["upcheck"];
                    StrSql = "update Payment set paymentstate=1,paynamtdate=getdate() Where PaymentId in (" + PaymentIdString + ") And PaymentState=2";
                    updateinsert = "update BuyPlanGoods set ispayment=1 where PaymentId in (" + PaymentIdString + ")";

                    HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Payment", StrSql, "../Bidder/ConfirmPayMent.aspx");
                    db.Command(StrSql);
                    db.Command(updateinsert);
                    db.Close();
                }
                showGridView();
            }
        }

    }

    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "Payment,SupplyCompany,Hospital";                                               //要查询的表明
        dbPage.Key = "PaymentId";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "distinct PaymentId,Payment.ProjectId,AccountId_YY,HospitalName,CompanyName_PS,UserCode_PS,PaymentName,PaymentPrice,Payment.AccountId_PS,PaymentStartDate,PaymentEndDate,Case PaymentState WHEN '2' Then '未确认' WHEN '1' Then '已确认' End As PaymentState,Case PaymentState WHEN '0' Then '' WHEN '1' Then 'disabled'  WHEN '2' Then '' End As disabled,PaynamtDate";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "PaymentState,PaynamtDate,PaymentId";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlAttorney.DataSource = dr;
        DlAttorney.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "";
        string PaymentName, PayStatus;

        PayStatus = DLPayStatus.SelectedValue;
        switch (PayStatus)
        {
            case "全部":
                strtemp += " (PaymentState=2 or PaymentState=1) And";
                break;
            case "未确认":
                strtemp += " PaymentState=2 And";
                break;
            case "已确认":
                strtemp += "PaymentState=1 And";
                break;
        }

        // strtemp += " Payment.ProjectId=" + PayMentProjectId.ToString() + " And Payment.AccountId_PS='" + PayMentPSId.ToString() + "' And Payment.AccountId_PS=SupplyCompany.AccountId_PS And Payment.ProjectId=SupplyCompany.ProjectId And Payment.AccountId_yy=Hospital.Accountid and";
        // 2007/08/22 
        strtemp += " Payment.AccountId_PS='" + PayMentPSId.ToString() + "' And Payment.AccountId_PS=SupplyCompany.AccountId_PS And Payment.AccountId_yy=Hospital.Accountid and";
        PaymentName = SysFun.ToTrim(txtPaymentName.Text);
        if (PaymentName != "")
        {
            strtemp += " PaymentName like '%" + PaymentName + "%' and";
        }

        //时间范围
        DateTime PaymentStartDate, PaymentEndDate;
        PaymentStartDate = Convert.ToDateTime("1900-1-1");
        PaymentEndDate = Convert.ToDateTime("1900-1-1");
        if (txtPaymentStartDate.Text.ToString() != "")
            PaymentStartDate = Convert.ToDateTime(txtPaymentStartDate.Text.ToString());
        if (txtPaymentEndDate.Text.ToString() != "")
            PaymentEndDate = Convert.ToDateTime(txtPaymentEndDate.Text.ToString());
        if (txtPaymentStartDate.Text.ToString() != "" && txtPaymentStartDate.Text.ToString() != "")
        {
            strtemp += " PaymentStartDate >='" + PaymentStartDate + "' and PaymentEndDate<='" + PaymentEndDate + "' And";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }

    #region TraDes 成员

    public string Name
    {
        get { return "回款单确认"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "结算管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            return _AccountType;
        }
    }

    #endregion

}
